<template>
	<div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:98%;left: 0px;top: 130px;bottom: 10px;outline: none;"></div>
</template>

<script>
import LuckyExcel from 'luckyexcel'
// import {
//     exportExcel
//   } from '@/utils/luckExcel.js'
	export default {
		data() { 								
			return {
                
			}
		},
		mounted() { 
			this.init()
		},
		methods: {
			// 初始化表格
			init() {
				var options = {
					container: 'luckysheet', //luckysheet is the container id
					showinfobar: false,
					lang: 'zh', // 设定表格语言
					
				}
				luckysheet.create(options) // eslint-disable-line
			},
			// 导入本地文件
			importExcel(file){
				// 传入一个 file 文件
				LuckyExcel.transformExcelToLucky(file, function(exportJson, luckysheetfile) {
					if (exportJson.sheets == null || exportJson.sheets.length == 0) {
						alert("Failed to read the content of the excel file, currently does not support xls files!");
						return;
					}
					// console.log(exportJson, luckysheetfile);
					window.luckysheet.destroy(); // eslint-disable-line
					window.luckysheet.create({ // eslint-disable-line
						container: 'luckysheet', //luckysheet is the container id
						showinfobar: false,
            lang: 'zh',
						data: exportJson.sheets,
						title: exportJson.info.name,
						userInfo: exportJson.info.name.creator,
						functionButton: '<button id="" class="btn btn-primary" onclick="uploadExcelData()" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">保存</button> <button id="" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 85px;" onclick="downExcelData()">下载</button>'
					});
				});
			},
			// 导入一个流文件
			importExcelUrl(url,name){
				// url:传入文件流的url地址,
				// name：文件名字
				LuckyExcel.transformExcelToLuckyByUrl(url,name ,function(exportJson, luckysheetfile) {
					if (exportJson.sheets == null || exportJson.sheets.length == 0) {
						alert("Failed to read the content of the excel file, currently does not support xls files!");
						return;
					} 
					window.luckysheet.destroy(); // eslint-disable-line
					window.luckysheet.create({ // eslint-disable-line
						container: 'luckysheet', //luckysheet is the container id
						showinfobar: false, 
            lang: 'zh',
						data: exportJson.sheets,
						title: exportJson.info.name,
						userInfo: exportJson.info.name.creator,
						functionButton: '<button id="" class="btn btn-primary" onclick="uploadExcelData()" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">保存</button> <button id="" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 85px;" onclick="downExcelData()">下载</button>'
					});
				});
			},
      // 推出编辑模式
      exitEdit(){
        luckysheet.exitEditMode(); // eslint-disable-line
      }
		}
	}
</script>

<style>
</style>
